<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>nicead</title>
    <link rel="stylesheet" href="/static/css/niceadindex.css"/>
    <script>
        function checkname() {
            registform = document.getElementById('registform');

            fd = new FormData(registform);

            xhr = new XMLHttpRequest();
            xhr.open('post', '/nicead/checkname/');
            xhr.send(fd);

            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4) {
                    if (xhr.status == 200 || xhr.status == 304) {
                        ret = JSON.parse(xhr.responseText);
                        console.log(ret.ret);
                        if(ret.ret==0){
                            console.log(ret.ret);
                            document.getElementById('keyong').style.display='';
                            document.getElementById('bukeyong').style.display='block';
                        }
                        else if(ret.ret==1){
                            console.log(ret.ret);
                            document.getElementById('keyong').style.display='block';
                            document.getElementById('bukeyong').style.display='';
                        }
                    }
                }
            }
        }


        function runsupport() {
            pic = document.getElementById('getmny');
            regis = document.getElementById('registerblok');
            log = document.getElementById('loginblok');
            upbtn = document.getElementById('upads');
            if (pic.style.display == '') {
                pic.style.display = 'block';
                regis.style.display = '';
                log.style.display = '';
                document.getElementById('support').value = '隐藏';
                document.getElementById('register').value = '注册';
                document.getElementById('login').value = '登陆';
                document.getElementById('upads').value = '上传';
            }
            else {
                pic.style.display = '';
                document.getElementById('support').value = '赞助';

            }

        }

        function runlogin() {
            pic = document.getElementById('getmny');
            regis = document.getElementById('registerblok');
            log = document.getElementById('loginblok');
            upbtn = document.getElementById('upads');
            if (log.style.display == '') {
                log.style.display = 'block';
                regis.style.display = '';
                pic.style.display = '';
                upbtn.style.display = '';
                document.getElementById('upads').value = '上传';
                document.getElementById('login').value = '隐藏';
                document.getElementById('register').value = '注册';
                document.getElementById('support').value = '赞助';
            }
            else {
                log.style.display = '';
                document.getElementById('support').value = '赞助';
                document.getElementById('register').value = '注册';
                document.getElementById('login').value = '登陆';

            }

        }

        function runregister() {
            pic = document.getElementById('getmny');
            regis = document.getElementById('registerblok');
            log = document.getElementById('loginblok');
            upbtn = document.getElementById('upads');
            if (regis.style.display == '') {
                regis.style.display = 'block';
                pic.style.display = '';
                log.style.display = '';
                upbtn.style.display = '';
                document.getElementById('upads').value = '上传';
                document.getElementById('register').value = '隐藏';
                document.getElementById('support').value = '赞助';
                document.getElementById('login').value = '登陆';
            }
            else {
                regis.style.display = '';
                document.getElementById('upads').value = '上传';
                document.getElementById('register').value = '注册';
                document.getElementById('login').value = '登陆';
                document.getElementById('support').value = '赞助';
            }

        }

        function runuploadads() {
            upbtn = document.getElementById('upads');
            pic = document.getElementById('getmny');
            regis = document.getElementById('registerblok');
            log = document.getElementById('loginblok');
            uploadblok = document.getElementById('uploadblok');
            if (upbtn.style.display == '') {
                upbtn.style.display = 'block';
                log.style.display = '';
                regis.style.display = '';
                pic.style.display = '';
                document.getElementById('upads').value = '隐藏';
                document.getElementById('login').value = '登陆';
                document.getElementById('register').value = '注册';
                document.getElementById('support').value = '赞助';
                uploadblok.style.display = 'block';
            }
            else {
                uploadblok.style.display = '';
                document.getElementById('upads').value = '上传';
                document.getElementById('support').value = '赞助';
                document.getElementById('register').value = '注册';
                document.getElementById('login').value = '登陆';

            }
        }

        function doregister() {
            registform = document.getElementById('registform');

            // console.log(document.forms["personinfoform"]["email"].value);

            fd = new FormData(registform);

            xhr = new XMLHttpRequest();
            xhr.open('post', '/personal/updatePersonInfo/');
            xhr.send(fd);

            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4) {
                    if (xhr.status == 200 || xhr.status == 304) {
                        // ret = JSON.parse(xhr.responseText);
                    }
                }
            }
        }

        function changegetmny() {
            var num = document.getElementById('paypic').name;

            if (num == 1) {
                document.getElementById('paypic').name = 2;
                document.getElementById('paypic').src = '/static/images/zfbget.jpg';
            }
            else {
                document.getElementById('paypic').name = 1;
                document.getElementById('paypic').src = '/static/images/wxget.jpg';
            }
        }


        function checkpasswd() {
            var pwd = document.getElementById('password').value;
            var cpwd = document.getElementById('cpasswd').value;
            if (pwd == cpwd) {
                document.getElementById('submitbtn').removeAttribute('disabled');

            } else {
                document.getElementById('submitbtn').setAttribute.disabled = 'disabled';
                alert('两次输入的密码不同，请重新输入')
            }
        }


        function showspan(obj) {
            var nextspan = document.getElementById('imgphoto').nextElementSibling;

            nextspan.style.display = 'block';

        }

        function hidespan(obj) {
            var nextspan = document.getElementById('imgphoto').nextElementSibling;
            nextspan.style.display = '';
        }

    </script>

</head>
<body>
<!--网页头部-->
<div class="topfa">
    <input type="button" name="back" id="back" value="返回">
    <input type="button" name="register" id="register" value="注册" onclick="runregister()">
    <input type="button" name="login" id="login" value="登陆" onclick="runlogin()">
    <input type="button" name="support" id="support" value="赞助" onclick="runsupport()">
    {% if request.session is not none %}
        <input type="button" name="upads" id="upads" value="上传" onclick="runuploadads()">
    {% endif %}
    <br>


    <!--收款码-->
    <div id="getmny">

        <img src="/static/images/wxget.jpg" alt="点击切换付款方式" id="paypic" onclick="changegetmny()" name="1">
    </div>
    <!--注册div-->
    <div class="registerblok" id="registerblok">

        <form action="/nicead/doregister/" method="post" id="registform">
            <table>
                <tr>
                    <td>用户名:</td>
                    <td><input type="text" name="uname" onblur="checkname()" required/><span id="keyong">可用</span><span
                            id="bukeyong">不可用</span></td>
                </tr>
                <tr>
                    <td>密码:</td>
                    <td><input type="password" id="password" name="password" required/></td>
                </tr>
                <tr>
                    <td>确认密码:</td>
                    <td><input type="password" name="cpasswd" id="cpasswd" onchange="checkpasswd()" required/></td>
                </tr>

                <tr>
                    <td></td>
                    <td><input type="submit" id="submitbtn" disabled value="提交"><input type="reset" value="重置"></td>
                </tr>
            </table>

        </form>
    </div>
    <!--登陆div-->
    <div class="loginblok" id="loginblok">

        <form action="/nicead/dologin/" method="post" id="loginform">
            <table>
                <tr>
                    <td>账号:</td>
                    <td><input type="text" name="uname" placeholder="请输入用户名"></td>
                </tr>
                <tr>
                    <td>密码:</td>
                    <td><input type="password" name="upass"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" value="登陆"><input type="reset" value="重置"></td>
                </tr>
            </table>
        </form>
    </div>
    <!--上传div-->
    <div class="uploadblok" id="uploadblok">
        <form action="/nicead/doupload/" method="post" enctype="multipart/form-data">
            <table>
                <tr>
                    <td>选择文件:</td>
                    <td><input type="file" name="adfile" id="uploadibtn"></td>
                </tr>
                <tr>
                    <td>展示信息:</td>
                    <td><input type="text" name="adtext" placeholder="请输入要展示的文字内容"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" value="提交"><input type="reset" value="重置"></td>
                </tr>
            </table>
        </form>
    </div>
</div>

<!--网页主体部分-->
<div class="secfa">

    <div class="secfablock"> <!--每个广告的模块-->
        <img class="imgphoto" id="imgphoto"  onmouseenter="showspan(this)" onmouseleave="hidespan(this)" src="/static/images/ad1.jpg" alt="有需要加微信">
        <span class="imgtext" id="imgtext">有需要加微信</span>
    </div>
{#    {% for i in xxx %}#}
{#        for x< i.length#}
{#        x++#}
{#    {% endfor %}#}
</div>

</body>
</html>